/**
 * 获取考试列表
 * @returns {function()}
 */
const getExamList = (formdata = {}) => {
  return (dispatch) => {
    ExamModel.find({
      status : 'end'
    },(err,doc)=>{
      if(!err){
        return Promise.resolve(dispatch({
          type: 'exam_list',
          info : doc
        }))
      }else{
        return Promise.reject('系统错误');
      }
    })
  }
}

/**
 * 获取用户列表
 * @returns {function()}
 */
const getUserList = (formdata = {}) => {
  return (dispatch) => {
    return new Promise(function(resolve, reject){
      lokiApi(formdata.path,function (collection) {
        if(formdata.user_name && formdata.user_idcard){
          var doc = collection.find({
            user_name : formdata.user_name,
            user_idcard : formdata.user_idcard
          });
        }else if(formdata.user_name){
          var doc = collection.find({
            user_name : formdata.user_name
          });
        }else if(formdata.user_idcard){
          var doc = collection.find({
            user_idcard : formdata.user_idcard
          });
        }else{
          var doc = collection.find({});
        };

        if(doc){
          resolve(dispatch({
            type : 'user_list',
            info : doc
          }));
        }
      });
    });
  }
}


export default {
  getExamList,
  getUserList
}